#include"string.h"


void test01()
{
    Wang::string s("12345");
    cout << s.c_str() << endl;  // 输出 12345

    Wang::string s1(10, 'x');
    cout << s1.c_str() << endl; // 输出 xxxxxxxxxx
}

void test02()
{
    Wang::string s1 = "12345";
    Wang::string s2 = s1;   // 拷贝构造

    Wang::string s3(10, 'x');
    cout << s3.c_str() << endl;
    s3 = s1;    // 赋值重载
    cout << s3.c_str() << endl;
}

void test03()
{
    Wang::string s1 = "12345";
    Wang::string s2(10, 'a');

    s1 = s2;
    cout << s1.c_str() << endl;
    s1.reserve(100);
    cout << s1.c_str() << endl;
}

void test04()
{
    Wang::string s1 = "123456789";
    auto it = s1.begin();
    while(it != s1.end())
    {
        cout << *it << ' ';
        ++it;
    }
    cout << endl;

    s1.push_back('a');
    s1.push_back('a');
    s1.push_back('a');
    s1.push_back('a');
    for(auto e : s1) // 范围for底层就是迭代器
        cout << e << ' ';
    cout << endl;
}

void test05()
{
    Wang::string s1 = "123456789";
    s1 += 'x';
    s1 += " Hello C++";
    Wang::string s2("1111111111");
    s1 += s2;
    cout << s1.c_str() << endl;
    for(int i = 0; i < s1.size(); i++)
        cout << s1[i];
}

void test06()
{
    Wang::string s1;
    for(int i = 0; i < 26; i++)
        s1.insert(s1.size(), i + 'a');
    for(auto e : s1) cout << e;
    cout << endl;

    s1.insert(2, "xxxxxxxxxxxxxxxxxxxxxx");
    for(auto e : s1) cout << e;
    cout << endl;

    s1.erase(2, 23);
    for(auto e : s1) cout << e;
    cout << endl;
}

void test07()
{
    Wang::string url = "https://editor.csdn.net/md/?articleId=151691236&spm=1011.2415.3001.9698";
    int p1 = url.find(':');
    cout << url.substr(0, p1).c_str() << endl;

    int p2 = url.find('/', p1 + 3);
    cout << url.substr(p1 + 3, p2 - (p1 + 3)).c_str() << endl;
    cout << url.substr(p2 + 1).c_str() << endl;
}

void test08()
{
    Wang::string s = "111";
    cin >> s;
    cout << s;
}
void test09()
{
    const char* s1 = "113";
    Wang::string s2 = "112";
    cout << (s1 < s2) << endl;
    cout << (s1 > s2) << endl;
    cout << (s1 == s2) << endl;
    cout << (s1 <= s2) << endl;
    cout << (s1 >= s2) << endl;
    cout << (s1 != s2) << endl << endl;

    Wang::string s3 = "1122";
    cout << (s2 < s3) << endl;
    cout << (s2 > s3) << endl;
    cout << (s2 == s3) << endl;
    cout << (s2 <= s3) << endl;
    cout << (s2 >= s3) << endl;
    cout << (s2 != s3) << endl;
}

void test10()
{
    Wang::string s;
    getline(cin, s);
    cout << s;
}

#include<vector>

void foo(Wang::string x)
{
}
void bar(const Wang::string& x)
{
}
Wang::string baz()
{
    Wang::string ret("world");
    return ret;
}
int main()
{
    Wang::string s0;
    Wang::string s1("hello");
    Wang::string s2(s0);
    Wang::string s3 = s1;
    s2 = s1;
    foo(s1);
    bar(s1);
    foo("temporary");
    bar("temporary");
    Wang::string s4 = baz();
    std::vector<Wang::string> svec;
    svec.push_back(s0);
    svec.push_back(s1);
    svec.push_back(baz());
    svec.push_back("good job");
}
